<template>
  <el-container>
    <!--    -->

  <el-header>
    <div>
      <img src="../assets/logo.png"/>
      <span>超市后台管理系统</span>
    </div>
    <el-button type="primary">退出</el-button>
  </el-header>
    <el-container>
  <!--  左侧菜单-->
  <el-aside>
    <div class="expo">|||</div>
    <el-menu
              :uniqueOpened="true"
              default-active="1"
              class="el-menu-vertical-demo"
              @open="handleOpen"
              @close="handleClose"
              background-color="#545c64"
              text-color="#fff"
              active-text-color="#ffd04b"
              >
              <el-submenu v-for="item in menuList" :key="item.id" :index="item.id+''">
                <template #title>
                  <i class="el-icon-location"></i>
                  <span>{{item.authName}}</span>
                </template>
<!--                当前菜单下面的子菜单，存children里面-->
                <el-menu-item v-for="subitem in item.children"  :key="subitem.id" :index="'/'+subitem.path">
                  <i class="el-icon-location"></i>
                  <span @click="toPath(subitem.path)">{{subitem.authName}}</span>
                </el-menu-item>
                </el-submenu>
            </el-menu>
  </el-aside>
<!--  右侧主题内容-->
  <el-main>
    <router-view></router-view>
  </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: "home",
  data(){
    return {
      menuList:[]
    }
  },
  created() {
    this.getMenuList();
  },
  methods: {
    //获取所有的左侧菜单
    getMenuList(){
      this.axios.get('menus').then(data=>{
        console.log(data)
        for (let i = 0; i < data.data.data.length; i++) {
          this.menuList.push(data.data.data[i]);
        }


      }).catch(err=>{
        console.log(err);
      })
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    //跳转路由
   toPath(path){
      this.$router.push(path);
   }
  }
}
</script>

<style scoped>
.el-container{
  height: 100%;
}

.el-header{
  display: flex;
  color:#fff;
  background-color: #0f0f0f;
/*  弹性盒模型 左右两边对齐*/
  justify-content: space-between;
  padding-left: 10px;
/*  内容居中对齐*/
  align-items: center;
  font-size: 24px;
}
.el-header div{
  display: flex;
}
.el-header div img{
  width: 50px;
  height: 50px;
  border-radius: 50px ;
}

.el-header div span{
  margin-left: 20px;
}

/*收缩条*/
.expo{
  background: #4a5064;
  font-size: 10px;
  color: #fff;
  line-height: 24px;
  text-align: center;
  user-select: none;
  cursor: pointer;
}

.el-aside{
  background: #33333f;
  height: 100%;
}
.el-main{
  background-color: #fff;
}
</style>
